//**********************************************************************************************************
// DVDCollection.java                            Author:20172323wyh
//
// Represents a collection of DVD movies.
//**********************************************************************************************************

import java.text.NumberFormat;

    public class DVDCollection implements Comparable <DVDCollection>
 {
    private DVD[] collection;
    private int count;
    private double totalCost;

    private String title, director;
    private int year;
    private double cost;
    private boolean bluray;

    //------------------------------------------------------------------------------------------------------
    // Constructor: Creates an initially empty collection.
    //------------------------------------------------------------------------------------------------------
     public DVDCollection(String title, String director, int year, double cost, boolean bluray)
     {
            collection = new DVD[100];
            count = 0;
            totalCost = 0.0;

            this.title = title ;
            this.director = director ;
            this.year = year;
            this.cost = cost;
            this.bluray = bluray ;

     }
    //------------------------------------------------------------------------------------------------------
    // Adds a DVD to the collection, increasing the size of the collection array if necessary.
    //------------------------------------------------------------------------------------------------------
    public void addDVD(String title, String director, int year, double cost, boolean bluray)
    {
        if (count == collection.length)
            increaseSize();

        collection[count] = new DVD(title, director, year, cost, bluray);
        totalCost += cost;
        count++;
    }

    //-----------------------------------------------------------------------------------------------------
    // Returns a report describing the DVD collection.
    //-----------------------------------------------------------------------------------------------------
    public String toString()
    {
            return title+"\t"+director+"\t"+ year+"\t"+ cost+"\t"+ bluray;
    }

    //----------------------------------------------------------------------------------------------------
    // Increases the capacity of the collection by creating a
    // larger array and copying the existing collection into it.
    //----------------------------------------------------------------------------------------------------
    private void increaseSize()
    {
        DVD[] temp = new DVD[collection.length * 2];

        for (int dvd = 0; dvd < collection.length; dvd++)
            temp[dvd] = collection[dvd];

        collection = temp;
    }

    public int compareTo(DVDCollection name)
        {
            int result;

            String nameTitle = name.getTitle();

            result = title.compareTo(nameTitle);
            return result;
        }
        public String getTitle ()
        {
            return title;
        }
}

